using UnityEngine;
using System;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditorInternal;
[CustomEditor(typeof(Attack))]
public class AttackEidtor : Editor {
    ReorderableList m_Attack;
    private void OnEnable()
    {
        var readon = serializedObject.FindProperty("m_attack");
        m_Attack = new ReorderableList(serializedObject,readon);
        m_Attack.elementHeight =  EditorGUIUtility.singleLineHeight+4;
        m_Attack.drawElementCallback = (rect, index, isActive, isFoused) =>
        {
            var element = readon.GetArrayElementAtIndex(index);
            rect.height -= 2;
            rect.y += 1;
            EditorGUI.PropertyField(rect, element);
        };
        m_Attack.onAddCallback = (list) => 
        {
            readon.arraySize++;
            list.index = readon.arraySize - 1;
        };
        m_Attack.drawHeaderCallback = (Rect) => EditorGUI.LabelField(Rect,readon.displayName);
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        m_Attack.DoLayoutList();
        serializedObject.ApplyModifiedProperties();
    }
}
[CustomPropertyDrawer(typeof(attackbehaviourpool))]
public class attackbehaviourDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        using (new EditorGUI.PropertyScope(position, label, property))
        {
            EditorGUIUtility.labelWidth = 80;
            position.height = EditorGUIUtility.singleLineHeight;
            var value =  new Rect(position) { width = position.width/2};
            var Attribute = new Rect(value) { x = position.x + position.width/2 };
            var attack = property.FindPropertyRelative("attackValue");
            var anim = property.FindPropertyRelative("animAttribute");
            attack.intValue = EditorGUI.IntSlider(value,attack.displayName,attack.intValue,0,10);
            EditorGUIUtility.labelWidth = 90;
            anim.objectReferenceValue = EditorGUI.ObjectField(Attribute, anim.displayName, anim.objectReferenceValue,typeof(Animation),false);
        }   
    }
}
#endif
[Serializable]
internal class attackbehaviourpool
{
    [SerializeField]
    internal  int attackValue = 0;
    [SerializeField]
    internal  AnimationClip animAttribute = null;
}
